import 'package:flutter/material.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/text_style.dart';
import 'package:mall/modules/model/home_entity.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:mall/router/navigator_util.dart';

class TabHomeGoodsCategory extends StatelessWidget {
  final List<HomeModelChannel> _homeModelChannel;

  TabHomeGoodsCategory(this._homeModelChannel);

  _goCategoryView(BuildContext context, HomeModelChannel channel) {
    print("${channel.id}");
    NavigatorUtil.goHomeCategoryGoodsPage(context, channel.name, channel.id);
  }

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: Container(
        padding: EdgeInsets.only(top: 20, bottom: 20, left: 15, right: 15),
        color: AppColors.C_FFFFFF,
        child: GridView.builder(
          physics: NeverScrollableScrollPhysics(),
          //禁止滚动
          shrinkWrap: true,

          //Vertical viewport was given unbounded height.  Column 中且套GridView、ListView的问题
          itemCount: _homeModelChannel.length,
          itemBuilder: (BuildContext context, int index) {
            //  return _getGridViewItem(categoryList[index]);
            return _getGridViewItem(context, _homeModelChannel[index]);
          },
          gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: 50,
            // childAspectRatio: 50/65,
            mainAxisExtent: 68,
            mainAxisSpacing: 15,
            crossAxisSpacing: 25,
          ),
        ),
      ),
    );
  }

  Widget _getGridViewItem(BuildContext context, HomeModelChannel channel) {
    return Center(
      child: InkWell(
        onTap: () => _goCategoryView(context, channel),
        child: Column(
          children: <Widget>[
            CachedImageView(42, 42, channel.iconUrl ?? ""),
            SizedBox(height: 8),
            Text(
              channel.name ?? "",
              style: APPTextStyle.color_222222_size_12,
            )
          ],
        ),
      ),
    );
  }
}
